﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_radioQuestionManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        

        string radio_question_title = "";
        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数
        try
        {
            //填充数据
            int page = Int32.Parse(Request.QueryString["page"].ToString().Trim());
            int limit = Int32.Parse(Request.QueryString["limit"].ToString().Trim());
            
            if (Request.QueryString["radio_question_title"] != null)
            {
                radio_question_title = Request.QueryString["radio_question_title"].ToString().Trim();
            }
            //question_type 
            //单选
           
                string sqlGetDataCount = "select count(*) from tb_radio_questions ";
                List<string> wheres = new List<string>();

                if (radio_question_title != "")
                {
                    wheres.Add("radio_question_title like '%" + radio_question_title + "%'");
                }
                string wh = "";
                if (wheres.Count > 0)
                {
                    wh = string.Join(" and ", wheres.ToArray());
                    sqlGetDataCount = sqlGetDataCount + " where " + wh;
                }
                count = Int32.Parse(SqlServer.ExecuteScalar(sqlGetDataCount));
                int page_temp = page;
                int limit_temp = limit;
                if (count < page * limit)
                {
                    limit = count - (page - 1) * limit;
                }
                page = (page_temp - 1) * limit_temp;

                string sql = "select top " + limit + " radio_question_id ,'单选题' as question_type, radio_question_title , option_a, option_b ,option_c, option_d ,course_id ,correct_answer from tb_radio_questions";

                if (wheres.Count > 0)
                {
                    sql = sql + " where " + wh + " and radio_question_id not in (select top " + page + "  radio_question_id from tb_radio_questions " + " where " + wh + ")";
                }
                else
                {
                    sql = sql + " where radio_question_id not in (select top " + page + "  radio_question_id from tb_radio_questions)";
                }
                table1 = SqlServer.GetDataTable(sql);
            }
            //多选
            //判断
            //解答

           
        catch (Exception ex)
        {
            Response.Write("<script>alert('有错误')</script>");
            Response.End();
        }
        string a = Json.ToJson(table1, count);
        Response.Write(Json.ToJson(table1, count));
        Response.End();

    
    }
}